package dialogs;

import android.app.Dialog;
import android.content.Context;
import android.os.Bundle;
import android.support.annotation.NonNull;
import android.support.annotation.StyleRes;
import android.support.v7.widget.AppCompatCheckBox;
import android.view.View;
import android.widget.TextView;

import com.example.administrator.newxlmedical.R;

import beans.UserManageBean;
import butterknife.BindView;
import butterknife.ButterKnife;
import butterknife.OnClick;
import custom.MyDialog;
//import me.codeboy.android.aligntextview.AlignTextView;

/**
 * Created by Administrator on 2018/5/10.
 */

public class UserManageEditDialog extends MyDialog {
    @BindView(R.id.tv_dialog_user_manage_edit_number)
    TextView tvNumber;
    @BindView(R.id.tv_dialog_user_manage_edit_name)
    TextView tvName;
    @BindView(R.id.tv_dialog_user_manage_edit_depart)
    TextView tvDepart;
    @BindView(R.id.tv_dialog_user_manage_edit_role)
    TextView tvRole;
    @BindView(R.id.tv_dialog_user_manage_edit_workkind)
    TextView tvWorkkind;
    @BindView(R.id.cb_dialog_user_manage_edit_enable)
    AppCompatCheckBox cbEnable;
    @BindView(R.id.cb_dialog_user_manage_edit_disable)
    AppCompatCheckBox cbDisable;
    @BindView(R.id.tv_dialog_user_manage_edit_cancle)
    TextView etCancle;
    @BindView(R.id.tv_dialog_user_manage_edit_sure)
    TextView etSure;

    public OnClickListener onClickListener;
    private UserManageBean bean;
    private boolean enable;


    public UserManageEditDialog(@NonNull Context context, @StyleRes int themeResId, UserManageBean bean, OnClickListener onClickListener) {
        super(context, themeResId);
        this.onClickListener = onClickListener;
        this.bean = bean;
    }

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.dialog_user_manage_edit);
        ButterKnife.bind(this);

        tvNumber.setText(bean.getNumber());
        tvName.setText(bean.getName());
        tvDepart.setText(bean.getDepartment());
        tvRole.setText(bean.getRole());
        tvWorkkind.setText(bean.getWorkKind());
        if (bean.isEnable()){
            cbEnable.setChecked(true);
            enable=true;
        }else{
            cbDisable.setChecked(true);
            enable=false;
        }
    }

    @OnClick({R.id.cb_dialog_user_manage_edit_enable, R.id.cb_dialog_user_manage_edit_disable,  R.id.tv_dialog_user_manage_edit_cancle, R.id.tv_dialog_user_manage_edit_sure})
    public void onViewClicked(View view) {
        switch (view.getId()) {
            case R.id.cb_dialog_user_manage_edit_enable:
                enable=true;
                cbDisable.setChecked(false);
                break;
            case R.id.cb_dialog_user_manage_edit_disable:
                enable=false;
                cbEnable.setChecked(false);
                break;

            case R.id.tv_dialog_user_manage_edit_cancle:
                dismiss();
                break;
            case R.id.tv_dialog_user_manage_edit_sure:
                onClickListener.onSure(enable,this);
                break;
        }
    }

    public interface OnClickListener {
        void onSure(boolean enable,UserManageEditDialog dialog);
    }
}
